/**
 * Live GPS Tracking Application
 * Main menu
 *
 * Copyright 2009, Ivar Clemens
 */

package nl.ivarclemens.gpstrack.ui;

import nl.ivarclemens.gpstrack.GPSTrack;
import nl.ivarclemens.gpstrack.Config;

import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.TextField;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;

import javax.microedition.lcdui.CommandListener;

/**
 *
 * @author ivar
 */
public class MenuUI extends List implements CommandListener {

    GPSTrack gpstrack;

    // Configuration object
    private Config config = null;

    // Menu items

    private Command exitCommand;

    public MenuUI(GPSTrack gpstrack)
    {
        super("Live Tracking", List.IMPLICIT);

        // Make sure configuration is loaded
        this.gpstrack = gpstrack;

        if(config == null)
            config = new Config();
        else
            this.config = gpstrack.getConfig();

        // Build configuration list

        exitCommand = new Command("Exit", Command.EXIT, 2);
        this.addCommand(exitCommand);

        this.append("Map", null);
        this.append("Status", null);
        this.append("Options", null);
        this.append("--", null);
        this.append("Current track", null);
        this.append("Enable network", null);
        this.append("Disable network", null);

        this.setCommandListener(this);
    }

    public void commandAction(Command c, Displayable d)
    {
        if(c == List.SELECT_COMMAND) {
            String selection = this.getString(this.getSelectedIndex());

            if(selection.compareTo("Current track") == 0)
                gpstrack.gotoScreen("track");

            if(selection.compareTo("Enable network") == 0)
                gpstrack.setNetwork(true);
            if(selection.compareTo("Disable network") == 0)
                gpstrack.setNetwork(false);

            //if(selection.compareTo("Toggle network") == 0)
            //    gpstrack.toggleNetwork();

            if(selection.compareTo("Options") == 0)
                gpstrack.gotoScreen("config");
            if(selection.compareTo("Status") == 0)
                gpstrack.gotoScreen("status");
            if(selection.compareTo("Map") == 0)
                gpstrack.gotoScreen("map");
        }

        if(c == exitCommand) {
            gpstrack.destroyApp(true);
            gpstrack.notifyDestroyed();
        }
    }

}
